create table ACCOUNT
(
	ID NUMBER not null primary key,
	USERNAME NVARCHAR2(50) not null,
	PASSWORD NVARCHAR2(50) not null,
	TOKEN NVARCHAR2(50)
);

CREATE SEQUENCE account_id_incre start with 1 increment by 1;

CREATE OR REPLACE TRIGGER new_account
  BEFORE INSERT
  ON account
  FOR EACH ROW
  BEGIN
    :NEW.id := account_id_incre.nextval;
  END;

CREATE OR REPLACE PROCEDURE create_account(usrname NVARCHAR2, pasword NVARCHAR2, tok NVARCHAR2) AS
BEGIN
  insert into account (username, password, token) VALUES (usrname, pasword, tok);
END;

BEGIN
  insert into account (username, password, token) VALUES ('aaaa', '123', NULL);
  insert into account (username, password, token) VALUES ('bbb', '123', NULL);
  insert into account (username, password, token) VALUES ('ccc', '123', NULL);
  insert into account (username, password, token) VALUES ('ddd', '123', NULL);
  insert into account (username, password, token) VALUES ('eee', '123', NULL);
  commit;
END;


create table POST
(
	ID NUMBER not null primary key,
	TITLE NVARCHAR2(50) not null,
	IMAGE NVARCHAR2(50),
	DESCRIPTION NVARCHAR2(500),
	CREATETIME DATE not null,
	ACCOUNTID NUMBER constraint POST_ACCOUNT_ID_FK references ACCOUNT on delete cascade
);

CREATE SEQUENCE post_id_incre start with 1 increment by 1;

CREATE OR REPLACE TRIGGER new_post_timestamp
  BEFORE INSERT
  ON post
  FOR EACH ROW
  BEGIN
    :NEW.id := post_id_incre.nextval;
    :NEW.createtime := sysdate;
  END;

CREATE OR REPLACE PROCEDURE del_post(iden NUMBER) AS
  BEGIN
    delete from post where id=iden;
  END;

CREATE OR REPLACE PROCEDURE create_post(titl NVARCHAR2, imag NVARCHAR2, descr NVARCHAR2, acid INTEGER) AS
  BEGIN
    insert into post (title, image, description, accountid) VALUES (titl, imag, descr, acid);
  END;

BEGIN
  insert into post (title, description, accountid) VALUES ('title1', 'des1', 1);
  insert into post (title, description, accountid) VALUES ('title2', 'des2', 2);
  insert into post (title, description, accountid) VALUES ('title3', 'des3', 3);
  insert into post (title, description, accountid) VALUES ('title4', 'des4', 1);
  insert into post (title, description, accountid) VALUES ('title5', 'des5', 2);
  insert into post (title, description, accountid) VALUES ('title6', 'des6', 3);
  commit;
END;